package com.xts.weinfo.ui.activity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.DividerItemDecoration;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;

import com.xts.weinfo.R;
import com.xts.weinfo.bean.NaviBean;
import com.xts.weinfo.net.BaseSubscriber;
import com.xts.weinfo.net.HttpUtil;
import com.xts.weinfo.net.RxUtils;
import com.xts.weinfo.ui.adapter.RlvNaviAdapter;

import java.util.ArrayList;

import qdx.stickyheaderdecoration.NormalDecoration;

public class NaviActivity extends AppCompatActivity {

    private RecyclerView mRlv;
    private RlvNaviAdapter mAdapter;

    public static void startAct(Context context) {
        context.startActivity(new Intent(context, NaviActivity.class));
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_navi);
        initView();
        initData();
    }

    private void initData() {
        HttpUtil.getInstance()
                .getWanService()
                .getNaviData()
                .compose(RxUtils.<NaviBean>rxSchedulerHelper())
                .subscribeWith(new BaseSubscriber<NaviBean>() {
                    @Override
                    public void onNext(NaviBean naviBean) {
                        if (naviBean.getData() != null
                                && naviBean.getData().size()>0){
                            mAdapter.setData(naviBean.getData());
                        }

                    }
                });
    }

    private void initView() {
        mRlv = (RecyclerView) findViewById(R.id.rlv);
        final ArrayList<NaviBean.DataBean> list = new ArrayList<>();
        mRlv.setLayoutManager(new LinearLayoutManager(this));
        mAdapter = new RlvNaviAdapter(this,list);
        mRlv.setAdapter(mAdapter);


        //设置一个悬浮头部,分割线
        NormalDecoration decoration = new NormalDecoration() {
            @Override
            public String getHeaderName(int pos) {
                return list.get(pos).getName();
            }
        };

        //分割线
        mRlv.addItemDecoration(decoration);
        //mRlv.addItemDecoration(new DividerItemDecoration(this,DividerItemDecoration.VERTICAL));
    }
}
